﻿/*
 * PsTFS is a set of PowerShell commands to manage and use Team Foundation Server. PowerShell 
 * effectiveness is combined with the power of TFS API to maximizes TFS capabilities.
 * 
 * Creator : Choulant Noham
 * Mail : choulant@gmail.com
 * Blog : http://choulant.blogspot.com
 * 
 */

using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using PsTFS.Objects;
using PsTFS.Objects.Methodes;
using System.Collections.ObjectModel;
using System.Linq;

namespace PsTFS.Commandes.Get
{
    /// <summary>
    /// Récupération des label
    /// </summary>
    [Cmdlet(VerbsCommon.Get, "Labels")]
    public class Get_Labels : PsCmdlet
    {
        /// <summary>
        /// Lancement du processus
        /// </summary>
        protected override void ProcessRecord()
        {
            List<VersionControlLabel> labels = null;
            if (this.Path == null || this.Path == string.Empty)
                this.Path = Context.GetContext().Project.Name;

            if (!this.Path.Contains(@"$/"))
                this.Path = @"$/" + this.Path;

            labels = new List<VersionControlLabel>(Methode_Service.VCS().QueryLabels(null, this.Path, null, true));

            WriteObject(labels);

            base.ProcessRecord();
        }

        /// <summary>
        /// Fin du processus
        /// </summary>
        protected override void EndProcessing()
        {
            Log.AddLog(null, "Get-Labels end");
            base.EndProcessing();
        }

        /// <summary>
        /// Object contenant Team Foundation Server
        /// </summary>
        [Parameter(Position = 0)]
        public TeamFoundationServer TFS
        {
            set { Context.GetContext().Tfs = value; }
        }
        /// <summary>
        /// Emplacement depuis le quel récupérer les label
        /// </summary>
        [Parameter(Position = 1)]
        public String Path { get; set; }
    }
}
